package offer06;


import java.util.Stack;

import node.ListNode;
import node.ListNodeManager;

public class Solution {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        ListNode head = ListNodeManager.createListNodeByArray(nums);
        reversePrint(head);
    }

    public static int[] reversePrint(ListNode head) {
        Stack<ListNode> stack = new Stack<>();
        int size = 0;
        while (head != null) {
            stack.push(head);
            head = head.next;
            size++;
        }

        ListNode listNode;
        int[] result = new int[size];
        int i = 0;
        while (!stack.empty()) {
            listNode = stack.pop();
            result[i] = listNode.val;
            System.out.println(listNode.val);
            i++;
        }
        return result;
    }
}
